cmake_minimum_required(VERSION 3.15)
project(runner LANGUAGES CXX)

add_executable(${BINARY_NAME} WIN32
  "flutter_window.cpp"
  "main.cpp"
  "run_loop.cpp"
  "utils.cpp"
  "win32_window.cpp"
  "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc"
  "card_reader_plugin.cpp"
  "Runner.rc"
  "runner.exe.manifest"
)
apply_standard_settings(${BINARY_NAME})
target_compile_definitions(${BINARY_NAME} PRIVATE "NOMINMAX" "FLUTTER_PLUGIN_IMPL")
target_compile_options(${BINARY_NAME} PRIVATE /wd4819)
target_link_libraries(${BINARY_NAME} PRIVATE flutter flutter_wrapper_app)
target_link_libraries(${BINARY_NAME} PRIVATE "${CMAKE_SOURCE_DIR}/native/hc_icrf64.lib")
target_include_directories(${BINARY_NAME} PRIVATE "${CMAKE_SOURCE_DIR}")
target_include_directories(${BINARY_NAME} PRIVATE "${CMAKE_SOURCE_DIR}/native")
add_dependencies(${BINARY_NAME} flutter_assemble)

# Copy DLL to output directory
set(DLL_NAME "hc_icrf64.dll")
set(DLL_SRC "${CMAKE_SOURCE_DIR}/native/${DLL_NAME}")
set(DLL_DST "$<TARGET_FILE_DIR:${BINARY_NAME}>")

add_custom_command(TARGET ${BINARY_NAME} POST_BUILD
    COMMAND ${CMAKE_COMMAND} -E copy_if_different
    "${DLL_SRC}"
    "${DLL_DST}"
    COMMENT "Copying ${DLL_NAME} next to ${BINARY_NAME}.exe"
)
